<template>
  <van-row>
    <van-col span="24">
      <!-- 分页查询商家信息 -->
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model:loading="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <van-cell v-for="item in list" :key="item" :title="item" />
        </van-list>
      </van-pull-refresh>
    </van-col>
  </van-row>
</template>

<script setup>
import { ref,getCurrentInstance, onMounted } from 'vue';
import { showNotify } from 'vant';

   const {proxy} = getCurrentInstance();

   //--------------------列表相关的变量和函数--------------------------

    const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);
    const refreshing = ref(false);

    const onLoad = () => {

      getBusinessByPage();

      // setTimeout(() => {
      //   if (refreshing.value) {
      //     list.value = [];
      //     refreshing.value = false;
      //   }

      //   for (let i = 0; i < 10; i++) {
      //     list.value.push(list.value.length + 1);
      //   }
      //   loading.value = false;

      //   if (list.value.length >= 40) {
      //     finished.value = true;
      //   }
      // }, 1000);
    };

    const onRefresh = () => {
      // 清空列表数据
      finished.value = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      loading.value = true;
      onLoad();
    };


    //------------------------分页查询商家数据-------------------------------

    const query = ref({
      pageNow: 1,
      pageCount: 5,
      businessName: ''
    })

    const pb = ref({
      totalRows: 0,
      data: []
    })

    const getBusinessByPage = ()=>{
      proxy.$axios({
        method: 'post',
        url: '/business/page',
        data: query.value
      }).then(res=>{
        let resultBean = res.data;
        if(resultBean.code == 200){
          pb.value = resultBean.data;
        }else{
          showNotify({ message: resultBean.msg });
        }
      }).catch(error=>{
        showNotify({ message: error.message });
      })
    }

    // onMounted(()=>{
    //   getBusinessByPage();
    // })

</script>

<style>
</style>
